home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / pine-use.c < prev    next >
C/C++ Source or Header  |  1996-03-15  |  6KB  |  205 lines

  1. #if !defined(lint) && !defined(DOS)
  2. static char rcsid[] = "$Id: pine-use.c,v 4.6 1996/03/15 07:13:42 hubert Exp $";
  3. #endif
  4. /*----------------------------------------------------------------------
  5.  
  6.             T H E    P I N E    M A I L   S Y S T E M
  7.  
  8.    Laurence Lundblade and Mike Seibel
  9.    Networks and Distributed Computing
  10.    Computing and Communications
  11.    University of Washington
  12.    Administration Builiding, AG-44
  13.    Seattle, Washington, 98195, USA
  14.    Internet: lgl@CAC.Washington.EDU
  15.              mikes@CAC.Washington.EDU
  16.  
  17.    Please address all bugs and comments to "pine-bugs@cac.washington.edu"
  18.  
  19.  
  20.    Pine and Pico are registered trademarks of the University of Washington.
  21.    No commercial use of these trademarks may be made without prior written
  22.    permission of the University of Washington.
  23.  
  24.    Pine, Pico, and Pilot software and its included text are Copyright
  25.    1989-1996 by the University of Washington.
  26.  
  27.    The full text of our legal notices is contained in the file called
  28.    CPYRIGHT, included with this distribution.
  29.  
  30.  
  31.    Pine is in part based on The Elm Mail System:
  32.     ***********************************************************************
  33.     *  The Elm Mail System  -  Revision: 2.13                             *
  34.     *                                                                     *
  35.     *             Copyright (c) 1986, 1987 Dave Taylor              *
  36.     *             Copyright (c) 1988, 1989 USENET Community Trust   *
  37.     ***********************************************************************
  38.  
  39.  
  40.   ----------------------------------------------------------------------*/
  41.  
  42. #include <stdio.h>
  43. #include <pwd.h>
  44. #include <sys/types.h>
  45. #include <sys/stat.h>
  46.  
  47. #ifndef MAILSPOOLPCTS
  48. #define MAILSPOOLPCTS "/usr/spool/mail/%s"
  49. /* #define MAILSPOOLPCTS "/usr/mail/%s" */
  50. #endif
  51.  
  52. #define DAYSEC (60*60*24)
  53.  
  54. main(argc, argv)
  55.      int argc;
  56.      char **argv;
  57. {
  58.     struct      passwd *pw;
  59.     char        filename[100], buf[100], *p;
  60.     struct stat statb;
  61.     long        now, inbox_mess, inboxes, inbox_mess_max;
  62.     int         core_files, c, core_id, count, sig_files;
  63.     int         user_count[6], so_far;
  64.     FILE       *f, *core;
  65.  
  66.     user_count[0] = 0; /* Last week */
  67.     user_count[1] = 0; /* Last 2 weeks */
  68.     user_count[2] = 0; /* Last month */
  69.     user_count[3] = 0; /* Last year */
  70.     user_count[4] = 0; /* Ever */
  71.     sig_files  = 0;
  72.     core_files = 0;
  73.     inboxes    = 0;
  74.     inbox_mess = 0;
  75.     inbox_mess_max = 0;
  76.  
  77.     now = time(0);
  78.     core = NULL;
  79.  
  80.     if(argc > 1) {
  81.         core_id = atoi(argv[1]);
  82.         if(core_id == 0){
  83.             fprintf(stderr, "Bogus core starting number\n");
  84.             exit(-1);
  85.         } else {
  86.             printf("Core collect starting at %d\n", core_id);
  87.             core = fopen("pine-core-collect.sh", "w");
  88.         }
  89.     } 
  90.  
  91.     so_far = 0;
  92.     while((pw = getpwent()) != NULL) {
  93.         so_far++;
  94.         if((so_far % 200) == 0) {
  95.             printf("%5d users processed so far\n", so_far);
  96.         }
  97.  
  98.         if(strcmp(pw->pw_dir, "/") == 0)
  99.           continue;
  100.  
  101.         sprintf(filename, "%s/.pinerc", pw->pw_dir);
  102.         if(stat(filename, &statb) < 0)
  103.           continue;
  104.         if(statb.st_mtime + 7 * DAYSEC > now) 
  105.             user_count[0]++;
  106.         else if(statb.st_mtime + 14 * DAYSEC > now)
  107.           user_count[1]++;
  108.         else if(statb.st_mtime + 30 * DAYSEC > now)
  109.           user_count[2]++;
  110.         else if(statb.st_mtime + 365 * DAYSEC > now) 
  111.           user_count[3]++;
  112.         else
  113.           user_count[4]++;
  114.  
  115.  
  116.         if(statb.st_mtime + 30 * DAYSEC >= now) {
  117.             count = mail_file_size(pw->pw_name);
  118.             if(count >= 0){
  119.                 inboxes++;
  120.                 inbox_mess += count;
  121.                 inbox_mess_max = inbox_mess_max > count ? inbox_mess_max:count;
  122.             }
  123.         }
  124.  
  125.         sprintf(filename, "%s/.signature", pw->pw_dir);
  126.         if(access(filename, 0) == 0)
  127.           sig_files++;
  128.  
  129.         sprintf(filename, "%s/core", pw->pw_dir);
  130.         if((f = fopen(filename, "r")) != NULL) {
  131.             fflush(stdout);
  132.             while((c = getc(f)) != EOF) {
  133.                 if(c == 'P'){
  134.                     p = buf;
  135.                     *p++ = c;
  136.                     while((c = getc(f)) != EOF) {
  137.                         *p++ = c;
  138.                         if(p > &buf[50]) {
  139.                             break;
  140.                         }
  141.                         if(c == ')') {
  142.                             break;
  143.                         }
  144.                     }
  145.                     *p = '\0';
  146.                     if(c == EOF)
  147.                       break;
  148.                     if(strcmp(&buf[strlen(buf) - 13], "(olivebranch)") == 0) {
  149.                         printf("%s\t%s\n", filename, buf + 14);
  150.                         core_files++;
  151.                         if(core != NULL) {
  152.                             fprintf(core, "mv %s core%d.%s\n", filename,
  153.                                     core_id++,pw->pw_name);
  154.                         }
  155.                         break;
  156.                     }
  157.                 }
  158.             }
  159.             fclose(f);
  160.         } else {
  161. /*            printf("%s\n", pw->pw_name); */
  162.         }
  163.     }
  164.  
  165.  
  166.     printf("%5d: last week\n", user_count[0]);
  167.     printf("%5d: last two weeks (+%d)\n", user_count[1] + user_count[0],
  168.             user_count[1]);
  169.     printf("%5d: last month (+%d)\n", user_count[2] + user_count[1] + user_count[0], user_count[2]);
  170.     printf("%5d: last year\n", user_count[3]);
  171.     printf("%5d: more than a year\n", user_count[4]);
  172.     printf("%5d: core files\n", core_files);
  173.     printf("%5d: Average messages in inbox  (%ld/%d)\n",
  174.            inbox_mess/inboxes, inbox_mess, inboxes);
  175.     printf("%5d: Largest inbox in messages\n", inbox_mess_max);
  176.     printf("%5d: Total users checked\n", so_far);
  177.     printf("%5d: signature files\n", sig_files);
  178. }
  179.  
  180.           
  181. mail_file_size(user)
  182.      char *user;
  183. {
  184.     int count = 0;
  185.     FILE *f;
  186.     char buf[20480];
  187.  
  188.     sprintf(buf, MAILSPOOLPCTS, user);
  189.  
  190.     f = fopen(buf, "r");
  191.     if(f  == NULL)
  192.       return(-1);
  193.  
  194.     while(fgets(buf, sizeof(buf), f) != NULL) {
  195.         if(strncmp(buf, "From ", 5) == 0)
  196.           count++;
  197.     }
  198.     fclose(f);
  199. /*    printf("%s %d\n", user, count); */
  200.     return(count);
  201. }
  202.     
  203.  
  204.     
  205.